package com.sbwebsocket.core.service.impl;

import com.sbwebsocket.core.config.WsAppConfig;
import com.sbwebsocket.core.redis.model.contants.WsMessageRedisKeyPrefix;
import com.sbwebsocket.core.service.ClientManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

/**
 * @Auther: GSJ
 * @Date: 2022/2/16
 * @Description:
 * @version: 1.0
 */
public class ClientManagerImpl implements ClientManager {

    @Autowired
    StringRedisTemplate redisTemplate;
    @Autowired
    WsAppConfig appConfig;


    @Override
    public boolean registerUserConnection(String clientKey) {
        redisTemplate.opsForValue().set(WsMessageRedisKeyPrefix.CLIENT_SERVER + clientKey,appConfig.getHostKey());
        return true;
    }

    @Override
    public boolean cleanUserConnection(String clientKey) {
        redisTemplate.delete(WsMessageRedisKeyPrefix.CLIENT_SERVER + clientKey);
        return true;
    }
}
